<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand" />
<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
<title>首页-精准微课堂</title>
	<%@ include file="/common/commonLib.jsp"%>
	<link rel="stylesheet" type="text/css" href="<c:url value='/css/student-index.css'/>" />
	<script src="<c:url value='/js/student-index.js'/>" type="text/javascript" charset="utf-8"></script>
</head>
<body class="home-template">
	<div class="container-fluid">
		<%@include file="/common/stu-header.jsp"%>
		<nav class="main-navigation" style="display:none;">
			<div class="container">
				<div class="row">
					<div class="col-sm-12 hidden-md hidden-lg">
						<div class="navbar-header">
							<span class="nav-toggle-button collapsed" data-toggle="collapse" data-target="#main-menu">
								<span class="sr-only">Toggle navigation</span>
								<i class="fa fa-bars"></i>
							</span>
						</div>
						<div class="collapse navbar-collapse" id="main-menu">
							<ul class="menu">
								<li role="presentation">
									<a id="menu-content1" class="show_today_course visible-xs visible-sm" title="今日课堂">今日课堂</a>
								</li>
								<li role="presentation">
									<a id="menu-content2" class="show_course visible-xs visible-sm" title="我的课程">我的课程</a>
								</li>		
							</ul>
						</div>
					</div>
				</div>
			</div>
		</nav>
		<!-- 简易版通知 -->
		<div id="simple-inform" style="display:block;">
			<div class="col-md-1"></div>
			<div class="col-md-10">
				<div id="inform-list" style="margin:2rem 0;box-shadow:3px 3px 3px 1px #2688DC;border:1px solid #4b9fe6;">
					
				</div>
			</div>
			<div class="col-md-1"></div>
		</div>
		<!-- 今日课堂和我的课程 -->
		<div class="content-wrap">
			<div class="container">
				<div class="row">				
					<aside class="col-md-12 sidebar">
						<div class="widget">
							<div class="title-calendar row">
								<ul>
									<li class="today-class-title ca">今日课堂</li>
									<li class="my-class-title">我的课程</li>
								</ul>
							</div>
							<div class="class-list">
								<div class="today-class-list">
									
								</div>
								<div class="my-class-list">
									<div class="row" id="course-list">
										
									</div>
								</div>
								
							</div>
						</div>
					</aside>
				</div>
			</div>
		</div>
	</div>
	<%@include file="/common/footer.jsp"%>
	<a id="back-to-top" style="display: inline;"><i class="fa fa-angle-up"></i></a>
	
</body>
<script>
var data =${data};
$(document).ready(function(){
	if(data.status!="success"){
		alert(data.message);
		return ;
	}
	initLesson(data.data.list);
	initInform();
	initCourse();
	$("#seachButton").click(searchCourse);
	$("#addClass").click(addCourse);
});
var getLesson=function(){
	$.get("<c:url value='/lesson/ajaxStudentCLesson'/>",function(data) {
		if(data.status=="success"){
			var lessons=data.data.list;
			initLesson(lessons);
		}
		
	});
}

var initLesson = function(lessons){
	var list=$(".today-class-list");
	
	if(lessons.length==0) {
		list.empty();
		list.append("<center><h4>今日无课！</h4></center>");
	} else {
		var s="";
		for(var i=0;i<lessons.length;i++){
			var arr = lessons[i].beginDate.split(" ");
			s+="<a href=\"<c:url value='/lessonTaskView/stuView?lessonId="+lessons[i].id+"'/>\" class=\"btn btn-default btn-block\">【<span>"+lessons[i].courseName+"</span>】[<span>"+lessons[i].location+"</span>]<span class=\"hidden-xs\">"+arr[0]+"</span> <span>"+arr[1]+"</span>-<span>"+lessons[i].endDate+"</span></a>";
		}
		list.empty();
		list.append(s);
	}
	
}

var addCourse = function(){
	var classId=$("input[name='id']").val();
	var json={
			classId:classId
	}
	$.post("<c:url value='/cscontrol/ajaxCreate'/>", {
		data : JSON.stringify(json)
	} ,function(data) {
		if(data.status=="success"){
			alert("success");
		}else{
			alert(data.message);
		}
	});
}

var searchCourse =function (){
	var search=$("input[name='search_class_code']").val();
	if(search==null||search==""){
		alert("请输入参数");
		return ;
	}
	var json={
			classCode:search
	}
	$.get( "<c:url value='/class/ajaxClassViewByCode'/>",{
		data : JSON.stringify(json)
	}, function(data) {
		if (data.status == "success") {
			$(".search-class-result").show();
			var classView=data.data.classView;
			$("#class_code").text(classView.courseCode);
			$("#class_name").text(classView.className);
			$("#class_course").text(classView.courseName);
			$("#class_teacher").text(classView.tname);
			$("#course_hour").text(classView.courseHour);
			$("#course_credit").text(classView.credit);
			$("#course_week").text(classView.sumWeeks);
			$("input[name='id']").val(classView.id);
		} else {
			alert(data.message);
		}
	});
}
var initInform = function(){
	$.get("<c:url value='/scccontrol/listInform'/>",function(data) {
		if(data.status=="success"){
			var inform=data.data.inform;
			if(inform.length < 1){
				$("#simple-inform").hide();
			}else{
				$("#simple-inform").show();
				var list=$("#inform-list");
				var s="";
				for(var i=0;i<inform.length;i++){
					s+="<div>";
					s+="<div id=\"inf-title\" style=\"padding:0 2rem;border:1px solid #4b9fe6;font-size:2rem;font-weight:600;\">"+inform[i].name+":</div>";
					s+="<div id=\"inf-content\" style=\"text-align:center;padding:1rem 2rem;\">"+inform[i].description+"</div>";
					if(i<inform.length-1){
						s+="<div style=\"border:2px solid #333;\"></div>";
					}				
					s+="</div>";
					
				}
				list.empty();
				list.append(s);	
			}					
		}		
	});
}

var initCourse = function(){
	$.get("<c:url value='/scccontrol/ajaxList'/>",function(data) {
		if(data.status=="success"){
			var courses=data.data.list;
			var list=$("#course-list");
			var s="";
			for(var i=0;i<courses.length;i++){
				s+="<div class=\"col-md-4\">";
				s+="<a href=\"<c:url value='/scccontrol/detailView?classId="+courses[i].classId+"'/>\">";
				s+="<div class=\"row course-info\">";
				s+="<div class=\"col-md-12 course-img hidden-xs\">";
				s+="<img src=\"<c:url value='/resource/picture/"+courses[i].image+"'/>\" />";
				s+="</div>";
				s+="<div class=\"col-md-12 course-name\">";
				s+="<div name=\"course_name\">";
				s+="课程名："+courses[i].courseName;
				s+="</div>";
				s+="<div name=\"course_teacher\">";
				s+="教师："+courses[i].tname;
				s+="</div>";
				s+="<div name=\"course_class\">";
				s+="班级："+courses[i].className;
				s+="</div>";
				s+="</div>";
				s+="</div>";
				s+="</a>";
				s+="</div>";
			}
			list.empty();
			list.append(s);			
		}
		
	});
}
</script>
</html>